<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xsl:stylesheet [
  <!ENTITY nbsp "&#x00A0;">
]>
<xsl:stylesheet
  version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:msxml="urn:schemas-microsoft-com:xslt"
  xmlns:site.library="urn:site.library"
  xmlns:site.defaults="urn:site.defaults"
  xmlns:umbraco.library="urn:umbraco.library" xmlns:Exslt.ExsltCommon="urn:Exslt.ExsltCommon" xmlns:Exslt.ExsltDatesAndTimes="urn:Exslt.ExsltDatesAndTimes" xmlns:Exslt.ExsltMath="urn:Exslt.ExsltMath" xmlns:Exslt.ExsltRegularExpressions="urn:Exslt.ExsltRegularExpressions" xmlns:Exslt.ExsltStrings="urn:Exslt.ExsltStrings" xmlns:Exslt.ExsltSets="urn:Exslt.ExsltSets" xmlns:examine="urn:examine"
  exclude-result-prefixes="msxml umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets site.library site.defaults examine ">

  <xsl:output method="xml" omit-xml-declaration="yes" indent="no"/>

  <xsl:variable name="Page" select="site.library:CurrentPage()"/>
  <xsl:variable name="SiteInfo" select="site.library:PageSite($Page/@id)"/>
  <xsl:variable name="Site" select="umbraco.library:GetXmlNodeById($SiteInfo/node/@id)"/>
  <xsl:variable name="DefaultPage" select="site.defaults:DefaultPage($Page/@id)"/>

  <xsl:template match="/">
    <xsl:call-template name="RenderPageTitle"/>
    <xsl:call-template name="RenderMetaTags"/>
  </xsl:template>

  <xsl:template name="RenderPageTitle">
    <xsl:variable name="pageTitle" select="site.library:ShortIf(string-length($Page/title)>0,$Page/title,$DefaultPage/title)"/>
    <xsl:variable name="siteTitle" select="site.library:ShortIf(string-length($SiteInfo/node/@title)>0,$SiteInfo/node/@title,$SiteInfo/node/@name)"/>
    <title>
      <xsl:value-of disable-output-escaping="yes" select="site.library:ShortIf(string-length($pageTitle)>0,$pageTitle,$Page/@nodeName)"/> | <xsl:value-of disable-output-escaping="yes" select="$siteTitle"/>
    </title>
  </xsl:template>
  
  <xsl:template name="RenderMetaTags">
    <xsl:variable name="metaAuthor" select="site.library:ShortIf(string-length($Page/metaAuthor)>0,$Page/metaAuthor,$Site/metaAuthor)"/>
    <xsl:variable name="metaKeywords" select="site.library:ShortIf(string-length($Page/metaKeywords)>0,$Page/metaKeywords, $DefaultPage/metaKeywords)"/>
    <xsl:variable name="metaDescription" select="site.library:ShortIf(string-length($Page/metaDescription)>0, $Page/metaDescription, $DefaultPage/metaDescription)"/>

    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <xsl:if test="string-length($metaAuthor)>0">
      <meta name="author" content="{$metaAuthor}"/>
    </xsl:if>
    <xsl:if test="string-length($metaKeywords)>0">
      <meta name="keywords" content="{$metaKeywords}" />
    </xsl:if>
    <xsl:if test="string-length($metaDescription)>0">
      <meta name="description" content="{$metaDescription}" />
    </xsl:if>
  </xsl:template>
</xsl:stylesheet>